5 10479
Strange
I have tried the following
<asp:DropDownList ID="DropDownListMake" runat="server"
CssClass="selectComparison" AutoPostBack="True"
OnSelectedIndexChanged="DropDownListMake_SelectedI ndexChanged" >
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
--------
protected void DropDownListMake_SelectedIndexChanged(object
sender,EventArgs e)
{
int x ;
if (!DropDownListMake.SelectedIndex.Equals("-1"))
x = Int32.Parse(DropDownListMake.SelectedValue);
}
--------
and it did work
perhaps the AutoPostBack="True"
doesn't fire if the DDL isn't bound to any data
-------------------------------------------
If my answer helped you please press "Yes" bellow
Adlai Maschiach http://blogs.microsoft.co.il/blogs/adlaim/
"Gearóid" wrote:
Sorry to repost, but please see below... this is driving me mad at
this point.
http://groups.google.com/group/micro...a7318a2f318442
The bizarre thing is the AutoPostBack="True" does fire. If I place a
breakpoint in my code on the Page_Load it is hit after I select
something in the DropDownList. But when it hitsthe line to see if
it's a postback or not it says it isn't. If I hover over if(!
this.IsPostBack) it tells me IsPostBack is false.
So even the the postback has fired and the breakpoint has been
triggered in my Page_load method, it thinks it's not a postback.
That's what baffles me...
snippet of Page_Load to bind data...
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
LoadMakes();
}
else // postback
{
nMakeID = int.Parse(DropDownListMake.SelectedValue);
}
}
private void LoadMakes()
{
DataTable dtMakes = new NewBike().GetMakes("Bike");
ClearDropDowns(true, true);
PopulateDropDown(DropDownListMake, dtMakes, "makeid", "makename",
"Make");
}
private void PopulateDropDown(DropDownList ddlList, DataTable dtData,
string strValueField, string strTextField, string strDefaultPromt)
{
ddlList.DataSource = dtData;
ddlList.DataValueField = strValueField;
ddlList.DataTextField = strTextField;
ddlList.DataBind();
ddlList.Items.Insert(0, new ListItem("Choose " + strDefaultPromt,
"-1"));
ddlList.SelectedIndex = 0;
}
Hi
each time you populate a DDL ( or every other control )
it's previous ViewState is Cleared/Ignored
that may be the cause for that
the SelectedIndexChange isn't fired
becuse according to the Page the contence has
change , thus irrelevant ( even if it's contence is the same )
-------------------------------------------
If my answer helped you please press "Yes" bellow
Adlai Maschiach http://blogs.microsoft.co.il/blogs/adlaim/
"Gearóid" wrote:
The bizarre thing is the AutoPostBack="True" does fire. If I place a
breakpoint in my code on the Page_Load it is hit after I select
something in the DropDownList. But when it hitsthe line to see if
it's a postback or not it says it isn't. If I hover over if(!
this.IsPostBack) it tells me IsPostBack is false.
So even the the postback has fired and the breakpoint has been
triggered in my Page_load method, it thinks it's not a postback.
That's what baffles me...
snippet of Page_Load to bind data...
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
LoadMakes();
}
else // postback
{
nMakeID = int.Parse(DropDownListMake.SelectedValue);
}
}
private void LoadMakes()
{
DataTable dtMakes = new NewBike().GetMakes("Bike");
ClearDropDowns(true, true);
PopulateDropDown(DropDownListMake, dtMakes, "makeid", "makename",
"Make");
}
private void PopulateDropDown(DropDownList ddlList, DataTable dtData,
string strValueField, string strTextField, string strDefaultPromt)
{
ddlList.DataSource = dtData;
ddlList.DataValueField = strValueField;
ddlList.DataTextField = strTextField;
ddlList.DataBind();
ddlList.Items.Insert(0, new ListItem("Choose " + strDefaultPromt,
"-1"));
ddlList.SelectedIndex = 0;
}
Thanks for your help. I got this sorted.
I have the following method
protected override object LoadPageStateFromPersistenceMedium()
{
LosFormatter Format = new LosFormatter();
//return Format.Deserialize (Request.Form["__VIEWSTATE"]);
string strSession = "";
if (Session["_ViewState"] != null)
{
strSession = Session["_ViewState"].ToString();
return Format.Deserialize(strSession);
}
else
{
return null;
}
}
This was being called in a basepage. Before it was called the
postback was there, but after it executed it was lost. It appears
this was clearing my viewstate, and in turn losing my postback This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Shiju Poyilil |
last post by:
Hi !
I have a requirement wherein i am binding a datalist which contains a label
(Caption for the field) and some literal hidden fields and a dropdown list.
When I am binding to the datalist.. only the labels (caption) and the
invisible literal controls are binded..
Now based on the invisible literal control values I get the information from...
|
by: Paul L |
last post by:
Hi, I have an issue with the OnSelectedIndexChanged event not firing for a
DropDownList control which is in the ItemTemplate of a DataList.
I have made an exact copy of the DropDownList control, and placed it outside
of the DataList and it fires the event just fine. So it's definitely to do
with it being in a template.
I've managed to...
|
by: Santosh |
last post by:
Dear all ,
i am writting following code.
if(Page.IsPostBack==false)
{
try
{
BindSectionDropDownlist();
|
by: Jason Wilson |
last post by:
I have two dropdownlists that are bound to the same datasource and I
have a couple of questions:
1) Because they are bound to the same datasource, I am assuming that
they only make 1 round trip to the DB server -- is that correct?
2) On a user's click of a button, one of the actions in the button
OnClick event is to set the...
|
by: jnoody |
last post by:
The problem I am having is with the SelectedIndexChanged event not
always firing or the SelectedIndex property not being correct when the
event does fire. The code is below, but here are some details first.
The DropDownList is actually a custom control called
DropDownListWithCommandEvent that inherits from DropDownList. The
reason I have...
| |
by: Damien |
last post by:
Hi guys,
I'm trying to learn ASP.NET and got a problem with DroDownList...
SelectedIndexChanged doesn't fire.
Maybe you'll be able to suggest something.
I think it may be connected with the fact I fill this list dynamically.
I use the following code:
|
by: =?iso-8859-1?B?R2VhcvNpZA==?= |
last post by:
Hi,
Wierd problem.
Using ASP.NET 2.0.
Have a DropDownList
- <asp:DropDownList ID="DropDownListMake" runat="server"
CssClass="selectComparison" AutoPostBack="True"
OnSelectedIndexChanged="DropDownListMake_SelectedIndexChanged" />
|
by: Lohboy |
last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET side.)
I have two DropDownList controls the second of which resides within an UpdatePanel control which responds to a change in the first DropDownList. I also have a hidden button nested inside the...
|
by: MattB |
last post by:
I have a (.Net 1.1) form with a Repeater and a DropDownList in the
ItemTemplate. I programmatically make the DDL Autopostback = true at
runtime based on the bound data. That works - I can see the postback
happen appropriately.
The DropDownList looks like this:
<asp:DropDownList id="ddMultiQty"...
|
by: Waldy |
last post by:
Hi there,
I have a web form with some DropDownList controls that I am
trying to trap the selection change and run the attached server code.
However, even thought the controls have the runat property set to server,
the event code does not get executed. Anyone have any ideas?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |